!function(s, e, t, i) {
    "use strict";
    var n = "WordpressUlikeNotifications"
      , a = {
        messageType: "success",
        messageText: "Hello World!",
        messageElement: "wpulike-message",
        notifContainer: "wpulike-notification"
    };
    function l(e, t) {
        this.element = e,
        this.$element = s(e),
        this.settings = s.extend({}, a, t),
        this._defaults = a,
        this._name = n,
        this.init()
    }
    s.extend(l.prototype, {
        init: function() {
            this._message(),
            this._container(),
            this._append(),
            this._remove()
        },
        _message: function() {
            this.$messageElement = s("<div/>").addClass(this.settings.messageElement + " wpulike-" + this.settings.messageType).text(this.settings.messageText)
        },
        _container: function() {
            s("." + this.settings.notifContainer).length || this.$element.append(s("<div/>").addClass(this.settings.notifContainer)),
            this.$notifContainer = this.$element.find("." + this.settings.notifContainer)
        },
        _append: function() {
            this.$notifContainer.append(this.$messageElement).trigger("WordpressUlikeNotificationAppend")
        },
        _remove: function() {
            var e = this;
            this.$messageElement.click(function() {
                s(this).fadeOut(300, function() {
                    s(this).remove(),
                    s("." + e.settings.messageElement).length || e.$notifContainer.remove()
                }).trigger("WordpressUlikeRemoveNotification")
            }),
            setTimeout(function() {
                e.$messageElement.fadeOut(300, function() {
                    s(this).remove(),
                    s("." + e.settings.messageElement).length || e.$notifContainer.remove()
                }).trigger("WordpressUlikeRemoveNotification")
            }, 8e3)
        }
    }),
    s.fn[n] = function(e) {
        return this.each(function() {
            new l(this,e)
        })
    }
}(jQuery, window, document),
function(n, e, s, t) {
    "use strict";
    var a = "WordpressUlike"
      , i = (n(e),
    n(s))
      , l = {
        ID: 0,
        nonce: 0,
        type: "",
        likeStatus: 0,
        counterSelector: ".count-box",
        generalSelector: ".wp_ulike_general_class",
        buttonSelector: ".wp_ulike_btn",
        likersSelector: ".wp_ulike_likers_wrapper"
    }
      , o = {
        "ulike-id": "ID",
        "ulike-nonce": "nonce",
        "ulike-type": "type",
        "ulike-status": "likeStatus"
    };
    function r(e, t) {
        for (var s in this.element = e,
        this.$element = n(e),
        this.settings = n.extend({}, l, t),
        this._defaults = l,
        this._name = a,
        this._refresh = !1,
        this.buttonElement = this.$element.find(this.settings.buttonSelector),
        this.generalElement = this.$element.find(this.settings.generalSelector),
        this.counterElement = this.generalElement.find(this.settings.counterSelector),
        o) {
            var i = this.buttonElement.data(s);
            void 0 !== i && (this.settings[o[s]] = i)
        }
        this.init()
    }
    n.extend(r.prototype, {
        init: function() {
            this.buttonElement.click(this._initLike.bind(this)),
            this.generalElement.hover(this._updateLikers.bind(this))
        },
        _ajax: function(e, t) {
            n.ajax({
                url: wp_ulike_params.ajax_url,
                type: "POST",
                cache: !1,
                dataType: "json",
                data: e
            }).done(t)
        },
        _initLike: function(t) {
            t.stopPropagation(),
            n(t.currentTarget).prop("disabled", !0),
            i.trigger("WordpressUlikeLoading", this.element),
            this.generalElement.addClass("wp_ulike_is_loading"),
            this._ajax({
                action: "wp_ulike_process",
                id: this.settings.ID,
                nonce: this.settings.nonce,
                status: this.settings.likeStatus,
                type: this.settings.type
            }, function(e) {
                this.generalElement.removeClass("wp_ulike_is_loading"),
                e.success ? this._updateMarkup(e) : this._sendNotification("error", e.data),
                n(t.currentTarget).prop("disabled", !1),
                i.trigger("WordpressUlikeUpdated", this.element)
            }
            .bind(this))
        },
        _updateMarkup: function(e) {
            switch (this.settings.likeStatus) {
            case 1:
                this.buttonElement.attr("data-ulike-status", 4),
                this.settings.likeStatus = 4,
                this.generalElement.addClass("wp_ulike_is_liked").removeClass("wp_ulike_is_not_liked"),
                this.generalElement.children().first().addClass("wp_ulike_click_is_disabled"),
                this.counterElement.text(e.data.data),
                this._controlActions("success", e.data.message, e.data.btnText, 4),
                this._refresh = !0;
                break;
            case 2:
                this.buttonElement.attr("data-ulike-status", 3),
                this.settings.likeStatus = 3,
                this.generalElement.addClass("wp_ulike_is_unliked").removeClass("wp_ulike_is_liked"),
                this.counterElement.text(e.data.data),
                this._controlActions("error", e.data.message, e.data.btnText, 3),
                this._refresh = !0;
                break;
            case 3:
                this.buttonElement.attr("data-ulike-status", 2),
                this.settings.likeStatus = 2,
                this.generalElement.addClass("wp_ulike_is_liked").removeClass("wp_ulike_is_unliked"),
                this.counterElement.text(e.data.data),
                this._controlActions("success", e.data.message, e.data.btnText, 2),
                this._refresh = !0;
                break;
            case 4:
                this._controlActions("info", e.data.message, e.data.btnText, 4),
                this.generalElement.children().first().addClass("wp_ulike_click_is_disabled");
                break;
            default:
                this._controlActions("warning", e.data.message, e.data.btnText, 0)
            }
            this._refresh && this._updateLikers()
        },
        _updateLikers: function() {
            this.likersElement = this.$element.find(this.settings.likersSelector),
            this.likersElement.length && !this._refresh || (this.generalElement.addClass("wp_ulike_is_getting_likers_list"),
            this._ajax({
                action: "wp_ulike_get_likers",
                id: this.settings.ID,
                nonce: this.settings.nonce,
                type: this.settings.type,
                refresh: this._refresh ? 1 : 0
            }, function(e) {
                this.generalElement.removeClass("wp_ulike_is_getting_likers_list"),
                e.success && (this.likersElement.length || (this.likersElement = n("<div>", {
                    class: e.data.class
                }).appendTo(this.$element)),
                e.data.template ? this.likersElement.show().html(e.data.template) : this.likersElement.hide()),
                this._refresh = !1
            }
            .bind(this)))
        },
        _controlActions: function(e, t, s, i) {
            this.buttonElement.hasClass("wp_ulike_put_image") ? 3 !== i && 2 !== i || this.buttonElement.toggleClass("image-unlike") : this.buttonElement.hasClass("wp_ulike_put_text") && this.buttonElement.find("span").html(s),
            this._sendNotification(e, t)
        },
        _sendNotification: function(e, t) {
            "1" === wp_ulike_params.notifications && n(s.body).WordpressUlikeNotifications({
                messageType: e,
                messageText: t
            })
        }
    }),
    n.fn[a] = function(e) {
        return this.each(function() {
            n.data(this, "plugin_" + a) || n.data(this, "plugin_" + a, new r(this,e))
        })
    }
}(jQuery, window, document),
function(t) {
    t(function() {
        t(this).bind("DOMNodeInserted", function(e) {
            t(".wpulike").WordpressUlike()
        })
    }),
    t(".wpulike").WordpressUlike()
}(jQuery);
